
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef HWCONF_H_
#define HWCONF_H_

#if !defined (COOLBIC) && !defined (COOLPAD) 
#error "Target not defined"
#endif

#include "stm32f10x_gpio.h"

// Pins

#define LED1_PORT   GPIOB
#define LED1_PIN    GPIO_Pin_8
#define LED2_PORT   GPIOB
#define LED2_PIN    GPIO_Pin_9

// Console

#define USART1_GPIO GPIOA
#define USART1_TX   GPIO_Pin_9 
        // rx (pin 10) sets automatically

// ADC to control voltages
#define ADC_COIL    GPIO_Pin_1
#define ADC_BATT    GPIO_Pin_0

// SPI1 - Flash

#define AT25_SPI                   SPI1

 #define CARD_SUPPLY_SWITCHABLE   0
 #define SOCKET_WP_CONNECTED      0
 #define SOCKET_CP_CONNECTED      0
 #define SPI_SD                   SPI1
 #define GPIO_CS                  GPIOA
 #define RCC_APB2Periph_GPIO_CS   RCC_APB2Periph_GPIOB
 #define GPIO_Pin_CS              GPIO_Pin_4
 #define DMA_Channel_SPI_SD_RX    DMA1_Channel2
 #define DMA_Channel_SPI_SD_TX    DMA1_Channel3
 #define DMA_FLAG_SPI_SD_TC_RX    DMA1_FLAG_TC2
 #define DMA_FLAG_SPI_SD_TC_TX    DMA1_FLAG_TC3
 #define GPIO_SPI_SD              GPIOA
 #define GPIO_Pin_SPI_SD_SCK      GPIO_Pin_5
 #define GPIO_Pin_SPI_SD_MISO     GPIO_Pin_6
 #define GPIO_Pin_SPI_SD_MOSI     GPIO_Pin_7
 #define RCC_APBPeriphClockCmd_SPI_SD  RCC_APB2PeriphClockCmd
 #define RCC_APBPeriph_SPI_SD     RCC_APB2Periph_SPI1
 /* - for SPI1 and full-speed APB2: 72MHz/4 */
 #define SPI_BaudRatePrescaler_SPI_SD  SPI_BaudRatePrescaler_4

// SPI2 - nRF24

#define NRF24_SPI                   SPI2
#define NRF24_SPI_CLK               RCC_APB1Periph_SPI2
#define NRF24_SPI_GPIO              GPIOB
#define NRF24_SPI_GPIO_CLK          RCC_APB2Periph_GPIOB
#define NRF24_SPI_PIN_SCK           GPIO_Pin_13
#define NRF24_SPI_PIN_MISO          GPIO_Pin_14
#define NRF24_SPI_PIN_MOSI          GPIO_Pin_15
#define NRF24_SPI_PIN_NSS           GPIO_Pin_12
#define NRF24_SPI_IRQn              SPI2_IRQn
#define NRF24_AUX_GPIO              GPIOA
#define NRF24_PIN_IRQ               GPIO_Pin_15
#define NRF24_PIN_CE                GPIO_Pin_8

#define NRF24_STBY                  GPIO_ResetBits(NRF24_AUX_GPIO, NRF24_PIN_CE)
#define NRF24_ACTIVE                GPIO_SetBits(NRF24_AUX_GPIO, NRF24_PIN_CE)

#define NRF24_CS_HIGH               GPIO_SetBits(NRF24_SPI_GPIO, NRF24_SPI_PIN_NSS)
#define NRF24_CS_LOW                GPIO_ResetBits(NRF24_SPI_GPIO, NRF24_SPI_PIN_NSS)

//-----------------

#define LED1_ON     GPIO_SetBits(LED1_PORT,LED1_PIN)
#define LED1_OFF    GPIO_ResetBits(LED1_PORT,LED1_PIN)
#define LED2_ON     GPIO_SetBits(LED2_PORT,LED2_PIN)
#define LED2_OFF    GPIO_ResetBits(LED2_PORT,LED2_PIN)
//-----------------

// Initialization functions

void gpio_hw_init(void);
void console_hw_init(void);
#if defined (COOLBIC)
void adc_hw_init(void);
void display_hw_init(void);
#endif
void radio_hw_init(void);


#endif /* HWCONF_H_ */
